package lh.model;

import java.util.Calendar;
import java.util.Date;

/**
 * TO DO
 *
 * @quther lianghao
 * @Date 2021/1/20
 */
public class UseDateInPutModel {
    private int id;
    /**
     * 购买日期
     */
    private Date payDate;
    /**
     * 延时天数
     */
    private int delayDays;
    /**
     * 活动天数
     */
    private int activeDays;
    /**
     * 信用额度天数
     */
    private int quotaDays;
    /**
     * 服务期（天）
     */
    private int serverDays;
    /**
     * 规定有效期
     */
    private int validDays;
    /**
     * 输入界面日期
     */
    private Date currentDate;
    /**
     * 开始使用日期
     */
    private Date beginDate;
    /**
     * 结束使用日期
     */
    private Date endDate;
    /**
     * 间隔天数
     */
    private int intervalDays;
    /**
     * 小计服务天数
     */
    private int totalServerDays;
    /**
     * 实际有效期
     */
    private int activeValidDays;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    /**
     * 输入界面日期-购买日期
     */
    private void setIntervalDays() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        int startDay = calendar.get(Calendar.DAY_OF_YEAR);
        calendar.setTime(payDate);
        int endDay = calendar.get(Calendar.DAY_OF_YEAR);
        this.intervalDays = startDay - endDay;
    }

    /**
     * 输入界面日期-购买日期
     *
     * @return间隔天数
     */
    public int getIntervalDays() {
        return intervalDays;
    }

    /**
     * 延时天数+活动天数+信用额度天数+服务期（天）
     */
    private void setTotalServerDays() {
        this.totalServerDays = delayDays + activeDays + serverDays + quotaDays;
    }

    /**
     * 延时天数+活动天数+信用额度天数+服务期（天）
     *
     * @return 小计服务天数
     */
    public int getTotalServerDays() {
        return totalServerDays;
    }

    /**
     * 实际有效期
     */
    private void setActiveValidDays() {
        int count;
        if (validDays - getIntervalDays() > 1) {
            count = 0;
        } else {
            count = validDays - getIntervalDays() - 1;
        }
        count += getTotalServerDays();
        this.activeValidDays = count > 0 ? count : 0;
    }

    /**
     * @return 实际有效期（天数）
     */
    public int getActiveValidDays() {
        return activeValidDays;
    }

    public Date getPayDate() {
        return payDate;
    }

    public void setPayDate(Date payDate) {
        this.payDate = payDate;
    }

    public int getDelayDays() {
        return delayDays;
    }

    public void setDelayDays(int delayDays) {
        this.delayDays = delayDays;
    }

    public int getActiveDays() {
        return activeDays;
    }

    public void setActiveDays(int activeDays) {
        this.activeDays = activeDays;
    }

    public int getQuotaDays() {
        return quotaDays;
    }

    public void setQuotaDays(int quotaDays) {
        this.quotaDays = quotaDays;
    }

    public int getServerDays() {
        return serverDays;
    }

    public void setServerDays(int serverDays) {
        this.serverDays = serverDays;
    }

    public int getValidDays() {
        return validDays;
    }

    public void setValidDays(int validDays) {
        this.validDays = validDays;
    }

    public Date getCurrentDate() {
        return currentDate;
    }

    public void setCurrentDate(Date currentDate) {
        this.currentDate = currentDate;
    }

    public Date getBeginDate() {
        return beginDate;
    }

    private void setBeginDate() {
        this.beginDate = currentDate;
    }

    private void setEndDate() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(getBeginDate());
        calendar.add(Calendar.DAY_OF_YEAR, getActiveValidDays());
        this.endDate = calendar.getTime();
    }

    /**
     * 开始计算
     */
    public void beginCalculate() {
        setIntervalDays();
        setTotalServerDays();
        setActiveValidDays();
        setBeginDate();
        setEndDate();
    }
}
